//
//  ButtonArrowView.m
//  CedarFinancePH
//
//  Created by lshenrong on 2019/1/2.
//  Copyright © 2019年 cedarhd. All rights reserved.
//

#import "ButtonArrowView.h"

@interface ButtonArrowView ()


@end

@implementation ButtonArrowView

//@synthesize isArrowFold = _isArrowFold;

+ (instancetype)buttonWithImage:(NSString *)imageName{
    ButtonArrowView *btn = [super buttonWithType:UIButtonTypeCustom];
    if (btn) {
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [btn addTarget:btn action:@selector(clickButtonAction) forControlEvents:UIControlEventTouchUpInside];
        btn.adjustsImageWhenDisabled = NO;
        btn.isArrowFold = YES;
        [btn showNoAnimate];
    }
    return btn;
}

- (void)clickButtonAction{
   _isArrowFold = !_isArrowFold;
    if (_isArrowFold) {
        [self show];
    }else{
        [self hide];
    }
    if(self.clickBlock){
        self.clickBlock(_isArrowFold);
    }
}

- (void)setIsArrowFold:(BOOL)isArrowFold{
    _isArrowFold = isArrowFold;
    if (_isArrowFold) {
        [self showNoAnimate];
    }else{
        [self hideNoAnimate];
    }
}

- (void)showNoAnimate{
    UIImageView *imageView = self.imageView;
     imageView.transform = CGAffineTransformMakeRotation(0);
}

- (void)hideNoAnimate{
    UIImageView *imageView = self.imageView;
    imageView.transform = CGAffineTransformMakeRotation(M_PI);
}



- (void)show{
    UIImageView *imageView = self.imageView;
    [UIView animateWithDuration:0.3 animations:^{
        imageView.transform = CGAffineTransformMakeRotation(M_PI);
    } completion:^(BOOL finished) {
    }];
}


- (void)hide {
    UIImageView *imageView = self.imageView;
    [UIView animateWithDuration:0.3 animations:^{
        imageView.transform = CGAffineTransformMakeRotation(0);
    } completion:^(BOOL finished) {
       
    }];
}




@end
